package come.bjpowernode.javase.io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
日志工具。
 */
public class Logger {
    public static void log(String msg){
        //指向一个资质文件
        PrintStream printStream = null;
        try {
            printStream = new PrintStream(
                    new FileOutputStream("logFile",true));
            //改变输出方法
            System.setOut(printStream);
            //当前日期时间
            Date nowTime = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss SSS");
            String strTime = sdf.format(nowTime);
            System.out.println(strTime + ":" + msg);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }
}
